import type { BasicTableColumn } from './types/table';

import type { ActionButton } from '@/components/table/src/types/action-button';

export interface BasicTableProps {
  /**
   * 标题
   */
  title?: string;
  /**
   * 标题提示
   */
  titleTooltip?: string;
  /**
   * 表格大小
   */
  size?: string;
  /**
   * 表格数据
   */
  dataSource?: Function;
  /**
   * 表格列
   */
  columns: BasicTableColumn[];
  /**
   * 是否分页
   */
  pagination?: boolean;
  /**
   * 请求之前处理
   */
  beforeRequest?: Function;
  /**
   * 数据请求
   */
  request: Function;
  /**
   * 请求参数
   */
  requestParams?: Recordable;
  /**
   * 是否参数变化自动请求
   */
  autoFetch?: boolean;
  /**
   * 请求后处理
   */
  afterRequest?: Function;
  /**
   * 是否树形表格
   */
  treeTable?: boolean;
  /**
   * 树形表格主键
   */
  treeField?: string;
  /**
   * 树形表格父节点字段
   */
  treeParentField?: string;
  /**
   * 树形表格子节点字段
   */
  treeChildrenField?: string;
  /**
   * 操作栏按钮
   */
  actionButtons?: ActionButton[];
  /**
   * 操作栏最多显示按钮
   */
  maxVisibleActionButtons?: number;
  /**
   * 主键字段
   */
  valueField?: string;
  /**
   * 是否多选
   */
  multiple?: boolean;
  /**
   * 选中的数据
   */
  defaultCheckedRowKeys?: Array<string | number>;
}

export const basicProps = {
  title: {
    type: String,
    default: null,
  },
  titleTooltip: {
    type: String,
    default: null,
  },
  size: {
    type: String,
    default: 'medium',
  },
  dataSource: {
    type: Function,
  },
  columns: {
    type: [Array] as PropType<BasicTableColumn[]>,
    default: () => [],
    required: true,
  },
  pagination: {
    type: [Object, Boolean],
    default: () => {},
  },
  beforeRequest: {
    type: Function as PropType<(...arg: any[]) => void | Promise<any>>,
    default: null,
  },
  request: {
    type: Function as PropType<(...arg: any[]) => Promise<any>>,
    default: null,
  },
  afterRequest: {
    type: Function as PropType<(...arg: any[]) => void | Promise<any>>,
    default: null,
  },
  rowKey: {
    type: [String, Function] as PropType<string | ((record: Recordable) => string)>,
    default: (_record: Recordable) => 'id',
  },
  striped: {
    type: Boolean,
    default: false,
  },
  treeTable: {
    type: Boolean,
    default: false,
  },
  treeField: {
    type: String,
    default: 'id',
  },
  treeParentField: {
    type: String,
    default: 'parentId',
  },
  treeChildrenField: {
    type: String,
    default: 'children',
  },
  actionButtons: Array as PropType<ActionButton[]>,
};
